package info.johnwheeler.gaestorage.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public abstract class AbstractUploadServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action = req.getParameter("action");
        if ("display".equals(action)) {           
            long id = Long.parseLong(req.getParameter("id").replace("_", "")); // WTF?            
            showRecord(id, req, resp);
        } else {
            showForm(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        handleSubmit(req, resp);
    }

    protected abstract void showForm(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException;

    protected abstract void handleSubmit(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException;

    protected abstract void showRecord(long id, HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException;
}
